const jwt = require("jsonwebtoken")

const tokenNext = (req, res, next) => {
    // 1.获取 token
    const authorization = req.headers['authorization']
    if (!authorization) {
        return res.send({
            code: 403,
            data: {},
            msg: '获取token失败'
        })
    }

    // 2.验证 token
    const token = authorization.replace('Bearer ', '');
    const result = jwt.verify(token, "123")
    req.token = result;
    next()
}

module.exports = {
    tokenNext
}